home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_q_t / trem.zip / COMM.C < prev    next >
Text File  |  1991-05-11  |  3KB  |  96 lines

  1. /************************************************************************
  2.  *
  3.  *    Copyright (c) 1991 Microsoft Corporation.  All Rights Reserved.
  4.  *
  5.  *-----------------------------------------------------------------------
  6.  *
  7.  *     Project:  Windows Terminal Example
  8.  *
  9.  *      Module:  comm.c
  10.  *
  11.  *      Author:  Bryan A. Woodruff (baw)
  12.  *
  13.  *
  14.  *     Remarks:  Handles writing and reading from COM port.
  15.  *
  16.  *   Revisions:  
  17.  *     01.00.000  5/10/91 baw   Wrote it
  18.  *
  19.  ************************************************************************/
  20.  
  21. #include "terminal.h"
  22.  
  23. /************************************************************************
  24.  *  int ReadCommBlock( HWND hWnd, LPSTR lpszBlock, int nMaxLength )
  25.  *
  26.  *  Description: 
  27.  *     Reads a block from the COM port and stuffs it into
  28.  *     the provided block.
  29.  *
  30.  *  Comments:
  31.  *      5/10/91  baw  Wrote it.
  32.  *
  33.  ************************************************************************/
  34.  
  35. int ReadCommBlock( HWND hWnd, LPSTR lpszBlock, int nMaxLength )
  36. {
  37.    int          nLength, nError ;
  38.    LOCALHANDLE  hTermInfo ;
  39.    NPTERMINFO   npTermInfo ;
  40.  
  41. #ifdef DISPLAY_ERRORS 
  42.    char         szError[ 10 ] ;
  43. #endif
  44.  
  45.    hTermInfo = GetWindowWord( hWnd, GWW_TERMINFO ) ;
  46.    if (NULL == (npTermInfo = (NPTERMINFO) LocalLock( hTermInfo )))
  47.       return ( FALSE ) ;
  48.  
  49.    while (nError = GetCommError( npTermInfo -> nCid, NULL))
  50.    {
  51. #ifdef DISPLAY_ERRORS
  52.       wsprintf( szError, "<CE-%d>", nError ) ;
  53.       WriteTerminalBlock( hWnd, szError, lstrlen( szError ) ) ;
  54. #endif
  55.    }
  56.  
  57.    nLength = ReadComm( npTermInfo -> nCid, lpszBlock, nMaxLength ) ;
  58.  
  59.    LocalUnlock( hTermInfo ) ;
  60.    return ( nLength ) ;
  61.  
  62. } /* end of ReadCommBlock() */
  63.  
  64. /************************************************************************
  65.  *  BOOL WriteCommByte( HWND hWnd, BYTE bByte )
  66.  *
  67.  *  Description: 
  68.  *     Writes a byte to the COM port.
  69.  *
  70.  *  Comments:
  71.  *      5/10/91  baw  Wrote it.
  72.  *
  73.  ************************************************************************/
  74.  
  75. BOOL WriteCommByte( HWND hWnd, BYTE bByte )
  76. {
  77.    LOCALHANDLE  hTermInfo ;
  78.    NPTERMINFO   npTermInfo ;
  79.  
  80.    hTermInfo = GetWindowWord( hWnd, GWW_TERMINFO ) ;
  81.    if (NULL == (npTermInfo = (NPTERMINFO) LocalLock( hTermInfo )))
  82.       return ( FALSE ) ;
  83.  
  84.    WriteComm( npTermInfo -> nCid, (LPSTR) &bByte, 1 ) ;
  85.  
  86.    LocalUnlock( hTermInfo ) ;
  87.  
  88.    return ( TRUE ) ;
  89.  
  90. } /* end of WriteCommByte() */
  91.  
  92. /************************************************************************
  93.  * End of File: comm.c
  94.  ************************************************************************/
  95.  
  96.